package com.lqq.service;

import com.lqq.dao.EmployeeMapper;
import com.lqq.entity.Employee;
import com.lqq.entity.EmployeeExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lqq on 2017/6/28.
 */
@Service
public class EmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;

    public List<Employee> getAllEmps() {
        return employeeMapper.selectByExampleWithDept(null);
    }

    public void addEmp(Employee employee) {
        employeeMapper.insertSelective(employee);
    }

    public boolean checkUser(String empName) {
        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        criteria.andNameEqualTo(empName);
        int count = employeeMapper.countByExample(employeeExample);
        return count == 0;
    }

    public void updateEmployee(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
    }

    public Employee getEmployee(int id) {
        return employeeMapper.selectByPrimaryKey(id);
    }

    public void deleteEmployee(Integer id) {
        employeeMapper.deleteByPrimaryKey(id);
    }

    public void deleteBatch(List<Integer> list) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(list);
        employeeMapper.deleteByExample(example);
    }
}
